package org.teachertools.services;

import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.DriverManager;

import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.xml.FlatDtdDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSet;

public class DbUnitExport {

    public static void main(String[] args) throws Exception {
        // database connection
        DriverManager.registerDriver(new com.mysql.jdbc.Driver());
        Connection jdbcConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/teachertools", "root", "");
        IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);

        // write DTD file
        String rootPath = "src/test/resources/org.teachertools/services/";
        FlatDtdDataSet.write(connection.createDataSet(), new FileOutputStream(rootPath + "dataset.dtd"));

        // full database export
        IDataSet fullDataSet = connection.createDataSet();
        FlatXmlDataSet.write(fullDataSet, new FileOutputStream(rootPath + "dataset.xml"));
    }
}
